const Router = require('koa-router')
const jwt = require('koa-jwt')
const router = new Router({
  prefix: '/questions/:questionId/answers/:answerId/comments'
})
const {
  checkCommentExist,
  checkCommentator,
  find,
  findById,
  create,
  update,
  delete: del
} = require('../controllers/comments')
const { SECRET } = require('../config')
const auth = jwt({ secret: SECRET })
// 获取评论列表
router.get('/', find)
// 获取指定评论
router.get('/:id', checkCommentExist, findById)
// 新建评论
router.post('/', auth, create)
// 修改指定评论
router.patch('/:id', auth, checkCommentExist, checkCommentator, update)
// 删除指定评论
router.delete('/:id', auth, checkCommentExist, checkCommentator, del)
module.exports = router
